package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.TravelContentReply;
import cn.wolfcode.trip.base.query.TravelContentReplyQueryObject;
import cn.wolfcode.trip.base.service.ITravelContentReplyService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("travelContentReplies")
public class TravelContentReplyController {
    @Autowired
    private ITravelContentReplyService travelContentReplyService;

    @PostMapping
    public Object saveReply(TravelContentReply travelContentReply) {
        JSONResult jsonResult = new JSONResult();
        try {
            travelContentReply.setUser(UserContext.getCurrentUser());
            travelContentReplyService.saveReply(travelContentReply);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.mark(e.getMessage());
        }
        return jsonResult;
    }
    @GetMapping("/replies")
    public Object getReplies(TravelContentReplyQueryObject qo){
        PageInfo pageInfo = travelContentReplyService.getReplies(qo);
        return pageInfo;
    }
    @GetMapping("/commentNum")
    public Object getCommentNum(Long travelId){
        int commentNum = travelContentReplyService.getCommentNum(travelId);
        return commentNum;
    }
}
